package com.mini6410;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.mini6410.ADC.ADCActivity;
import com.mini6410.EEPROM.EEPROMActivity;
import com.mini6410.HelloMini6410.HelloMini6410Activity;
import com.mini6410.LED.LEDActivity;
import com.mini6410.PWM.PWMActivity;

public class MainActivity extends Activity implements OnItemClickListener {
	private  static final String TAG = "MainActivity";

	//ListView
	ListView mListView = null;

	//TextView 
	TextView mEmptyView = null;

	public void onCreate(Bundle savedInstanceState) {
		Log.i(TAG,"onCreate");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		initUI();
		initData();
	}

	/**
	 * 
	 * initUI: 初始化UI
	 *
	 * @param   
	 * @return     
	 * @throws 
	 */
	public void initUI(){
		mEmptyView=(TextView)findViewById(R.id.empty);  

		mListView=(ListView)findViewById(R.id.listview);  

		mListView.setOnItemClickListener(this);

		mListView.setEmptyView(mEmptyView);
	}


	/**
	 * 
	 * initData: 初始化ListView的数据适配器
	 *
	 * @param   
	 * @return     
	 * @throws 
	 */
	public void initData(){
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(  
				this, R.array.demos, android.R.layout.simple_list_item_1);  
		mListView.setAdapter(adapter);
	}



	/**
	 * 
	 * onItemClick: 响应ListView的Item点击动作
	 *
	 * @param   
	 * @return     
	 * @throws 
	 */
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		Intent intent = new Intent();
		switch (position) {
		case 0:
			intent.setClass(this, HelloMini6410Activity.class);
			break;
		case 1:
			intent.setClass(this, LEDActivity.class);
			break;
		case 2:
			intent.setClass(this, PWMActivity.class);
			break;
		case 3:
			intent.setClass(this, ADCActivity.class);
			break;
		case 4:
			intent.setClass(this, EEPROMActivity.class);
			break;
			}
		startActivity(intent);
	}
}